﻿package mortal.game.scene3D.fight.dramaEffect
{
    import baseEngine.core.*;
    import com.gengine.utils.pools.*;
    import mortal.game.scene3D.fight.dramaEffect.data.*;
    import mortal.game.scene3D.fight.dramaEffect.rule.*;

    public class DramaEffectArray extends Object
    {
        private var _aryMoveData:Array;
        private var _currentIndex:int = 0;
        private var _effectPlayer:Pivot3D;
        private var _endCallBack:Function;

        public function DramaEffectArray()
        {
            return;
        }// end function

        public function play(param1:Pivot3D, param2:Array, param3:Function) : void
        {
            this._aryMoveData = param2;
            this._effectPlayer = param1;
            this._endCallBack = param3;
            this.playNext();
            return;
        }// end function

        private function playNext() : void
        {
            var _loc_1:Function = null;
            if (this._currentIndex >= this._aryMoveData.length)
            {
                this.playEnd();
                return;
            }
            if (this._currentIndex == (this._aryMoveData.length - 1))
            {
                _loc_1 = this.playEnd;
            }
            else
            {
                _loc_1 = this.playNext;
            }
            var _loc_2:* = this._aryMoveData[this._currentIndex] as DramaMoveData;
            var _loc_3:String = this;
            var _loc_4:* = this._currentIndex + 1;
            _loc_3._currentIndex = _loc_4;
            this.playDramaMove(this._effectPlayer, _loc_2, _loc_1);
            return;
        }// end function

        private function playDramaMove(param1:Pivot3D, param2:DramaMoveData, param3:Function) : void
        {
            if (param2.moveType == DramaMoveType.MoveTypeUniform)
            {
                (ObjectPool.getObject(DramaUniformRule) as DramaUniformRule).play(param1, param2, param3);
            }
            else if (param2.moveType == DramaMoveType.MoveTypeTween)
            {
                (ObjectPool.getObject(DramaTweenRule) as DramaTweenRule).play(param1, param2, param3);
            }
            return;
        }// end function

        private function playEnd() : void
        {
            if (this._endCallBack != null)
            {
                this._endCallBack.call();
            }
            this.dispose();
            return;
        }// end function

        public function dispose() : void
        {
            this._aryMoveData = [];
            this._currentIndex = 0;
            this._effectPlayer = null;
            this._endCallBack = null;
            ObjectPool.disposeObject(this);
            return;
        }// end function

    }
}
